﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Library.DbObjects.Factory;
namespace NameplateReport
{
    public partial class LoginForm : Form
    {
        BaseObjectFactory Instance = new BaseObjectFactory();
        HomeForm homeForm;
        public LoginForm()
        {
            InitializeComponent();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            Instance.Query.SqlBuilder = string.Format("select * from Users where userName='{0}' and password='{1}'", txtUserName.Text, txtPassword.Text);
            var user = Instance.Query.ExecuteForObject("Users");
            if (user != null)
            {
                if (homeForm == null)
                {
                    homeForm = new HomeForm();
                }
                this.Visible = false;
                homeForm.Show();
                homeForm.FormClosed += (ss, ee) => { Close(); };
            }
        }

        private void txtPassword_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                btnLogin_Click(sender, null);
            }
        }
    }
}
